from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from books.models import BooksInfo
from books.serializer import BooksSerializer
# Create your views here.

# def indexView(request):
#     title = "首页"
#     booklist = BooksInfo.objects.all()
#     # 渲染
#     return render(request, "index.html", locals())

class indexView(APIView):
    def get(self, request):
        context = {'state': 'success', 'msg': "获取成功", 'data': {}}
        context['data']['BooksInfo'] = []
        c = BooksInfo.objects.all()
        context['data']['BooksInfo'].append(BooksSerializer(instance=c[::], many=True).data)

        return Response(context)